﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using ms;

namespace FairyGUI
{
    /// <summary>
    /// Base class for all kind of fonts. 
    /// </summary>
    public class BaseFont
    {
        /// <summary>
        /// The name of this font object.
        /// </summary>
        public string name { get; protected set; }

        /// <summary>
        /// The texture of this font object.
        /// </summary>
        public NTexture mainTexture { get; protected set; }

        /// <summary>
        ///  Can this font be tinted? Will be true for dynamic font and fonts generated by BMFont.
        /// </summary>
        public bool canTint;

        /// <summary>
        /// If true, it will use extra vertices to enhance bold effect
        /// </summary>
        public bool customBold;

        /// <summary>
        /// If true, it will use extra vertices to enhance bold effect ONLY when it is in italic style.
        /// </summary>
        public bool customBoldAndItalic;

        /// <summary>
        /// If true, it will use extra vertices(4 direction) to enhance outline effect
        /// </summary>
        public bool customOutline;

        /// <summary>
        /// The shader for this font object.
        /// </summary>
        public string shader;

        /// <summary>
        /// Keep text crisp.
        /// </summary>
        public bool keepCrisp { get; protected set; }

        /// <summary>
        /// 
        /// </summary>
        public int version { get; protected set; }

        public virtual Color color => Color.White;
        public virtual float scale => 1f;

        protected const float SupScale = 0.58f;
        protected const float SupOffset = 0.33f;

        public BaseFont()
        {
        }

        public virtual int DrawLine(float x, float y, float width, int fontSize, int type,
            List<Vector3> vertList, List<Vector2> uvList, List<Vector2> uv2List, List<Color> colList)
        {

            return 0;
        }

        public virtual int DrawGlyph(float x, float y,
            List<Vector3> vertList, List<Vector2> uvList, List<Vector2> uv2List, List<Color> colList)
        {
            return 0;
        }
        public virtual int GetLineHeight(int size)
        {
            return 5;
        }
        public virtual bool HasCharacter(char ch)
        {
            return true;
        }

        public virtual void PrepareCharacters(string text)
        {
        }

        public virtual bool GetGlyph(char ch, out float width, out float height, out float baseline)
        {
            /*width = 0;
			height = 0;
			baseline = 0;
			return false;*/

            width = 15;
            height = 15;
            baseline = 0;
            return true;
        }

        public virtual void SetFormat(TextFormat format, float fontSizeScale)
        {
        }

        public virtual void UpdateGraphics(NGraphics graphics)
        {

        }

    }

    /// <summary>
    /// Character info.
    /// </summary>
    public struct GlyphInfo
    {
        public Vector2 vertMin;
        public Vector2 vertMax;
        public Vector2 uvBottomLeft;
        public Vector2 uvTopLeft;
        public Vector2 uvTopRight;
        public Vector2 uvBottomRight;
        public float width;
        public float height;
        public int channel;
    }
}
